<!DOCTYPE html>
<html>
    
    <head>
        <title>TCP加速网关</title>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <!-- Bootstrap -->
        <link href="View/FHL/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="View/FHL/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="View/FHL/assets/styles.css" rel="stylesheet" media="screen">
        <link href="View/FHL/assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <link href="View/FHL/vendors/jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen">
        <link href="public/css/font-awesome.min.css" rel="stylesheet" media="screen">
        <!--[if lte IE 8]>
        <script language="javascript" type="text/javascript" src="View/FHL/vendors/flot/excanvas.min.js"></script>
        <![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>

        <![endif]-->
        <script src="View/FHL/vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>
    <style>
        td{
            word-wrap:break-word;
            text-align: center;
        }
        table{
            table-layout:fixed ;
        }
        #setMode {
            height:700px;
            /* SET THE WIDTH OF THE MODAL 设置Modal的宽度*/
            width:800px;
        }
        #setMode .modal-body {
            height:600px;
            max-height: 600px;
            /* SET THE WIDTH OF THE MODAL 设置Modal的宽度*/
            width:700px;
            /* CHANGE MARGINS TO ACCOMODATE THE NEW WIDTH (original = margin: -250px 0 0 -280px;) */
        /*margin:-250px -450px;*/
        }
    </style>
    
    <body>
    {include h}
        <div class="container-fluid">

            <div class="row-fluid">
                {include l}
                <!--/span-->
                <div class="span10" id="content">
                    <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">TCP加速网关</div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                    

                                    <div class="alert alert-info alert-block">
                                        <a class="close" data-dismiss="alert" href="#">×</a>
                                        <h4 class="alert-heading">TCP连接发起端的机器路由设置方法</h4>
                                        route add x.x.x.x(目的ip) mask 255.255.255.255 x.x.x.x(本地加速网关ip) 
                                        <h4 class="alert-heading">路由删除方法</h4>
                                        route delete x.x.x.x(目的ip)
                                    </div>
                                </div>
                                <div class="span12">
                                    <div class="span8">
                                        <table class="table"  >
                                            <thead class="success">
                                            <tr>
                                                <th style="width: 5%">ID</th>
                                                <th style="width: 10%;word-wrap:break-word;">名称</th>
                                                <th style="width: 10%;word-wrap:break-word;">监听端口</th>
                                                <th style="width: 25%;word-wrap:break-word;">远端互联IP</th>
                                                <th style="width: 15%;word-wrap:break-word;">远端互联端口</th>
                                                <th style="width: 25%;word-wrap:break-word;">加速网段</th>
                                                <th style="width: 10%">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody id="table_body">
                                                {foreach $Gtask as $V}
                                                    {if $V['ID']%2==0}
                                                    <tr class="success">
                                                    {else}
                                                    <tr class="info">
                                                    {/if}
                                               
                                                    <td style="width: 5%" >{$V.ID}</td>
                                                    {if $V['isrun']== true}
                                                    <td style="width: 10%" ><span class="badge badge-success">{$V.name}</span></td>
                                                    {else}
                                                    <td style="width: 10%" ><span class="badge badge-important">{$V.name}</span></td>
                                                    {/if}
                                                    <td style="width: 10%" >{$V.localport}</td>
                                                    <td style="width: 30%" >{$V.remoteip}</td>
                                                    <td style="width: 10%" >{$V.remoteport}</td>
                                                    <td style="width: 30%" >{$V.speednet}</td>
                                                    <td style="width: 5%" >
                                                        <div class="btn-group">
                                                            <button class="btn btn-info btn-mini showSetMode" data-id="{$V.ID}" 
                                                            data-name='{$V.name}' data-localport='{$V.localport}'
                                                            data-remoteip='{$V.remoteip}' data-remoteport='{$V.remoteport}' data-speednet='{$V.speednet}'>
                                                                <i class="icon-wrench icon-white"></i>
                                                            </button> 
                                                        </div>
                                                    </td>
                                                </tr>           
                                                {/foreach}
                                            </tbody>
                                        </table>
                                    </div>
                                    <!--三个加速操作按钮-->
                                    <div class="span4">
                                        <!--
                                        <div class="span6" style="display: none;">
                                            <div style="clear: both">
                                                <label class="control-label" for="netmask" style="float: left;padding-top: 9px;width: 100px;text-align: right" >启动模式：</label>
                                                <select id="mode" style="float: left;padding-top: 9px">
                                                    <option value="c">客户端</option>
                                                    <option value="s">服务端</option>
                                                </select>
                                            </div>
                                            <div style="clear: both" id="divRip">
                                                <label class="control-label" for="rip" style="float: left;padding-top: 9px;width: 100px;text-align: right" >远端互联IP：</label>
                                                <input class="input-xlarge focused" id="rip" style="float: left;margin-top: 5px"
                                                    type="text" value="">
                                            </div>
                                        </div>
                                        -->
                                        <div class="" style="display: flex;align-items: center;height: 500px;">
                                            <button data-href="?set/t.html"  style="margin-left: 10px;width: 110px;height: 300px" id="start"
                                                    class="btn btn-success btn-large ">开加速</button>
                                            <button data-href="?set/t.html"  style="margin-left: 10px;width: 110px;height: 300px" id="stop"
                                                    class="btn btn-danger btn-large ">关加速</button>
                                            <button data-href="?set/t.html"  style="margin-left: 10px;width: 110px;height: 300px" id="autoTest"
                                                    class="btn btn-info btn-large ">自检</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                        <!--测试反馈界面-->
                        <div id="sysTestModal" class="modal hide" style="width: 50%;
                            top: 50%;
                            left: 70%;
                            transform: translate(-50%, -50%);">
                            <div class="modal-header">
                                <button data-dismiss="modal" class="close" type="button">&times;</button>
                                <h3>测试反馈</h3>
                            </div>
                            <div class="modal-body" id="sysTestContent">
                            </div>
                        </div>
                        <!--/测试反馈界面-->
                    </div>
                </div>
            </div>
            <hr>
            {include f}
        </div>
        <!-- set mode  -->
        <div id="setMode" class="modal hide">
            <div class="modal-header">
                <button data-dismiss="modal" class="close" type="button">&times;</button>
                <h3>设置任务参数</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal form">
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label" >监听端口</label>
                            <div class="controls">
                                <input class="input-xlarge focused"  name="localport" type="text" value="">
                            </div>
                        </div>
                        <div class="control-group" >
                            <label class="control-label">远端互联IP </label>
                            <div class="controls">
                                <input class="input-xlarge focused"  name="remoteip" type="text" value="">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" >远端互联端口</label>
                            <div class="controls">
                                <input class="input-xlarge focused"  name="remoteport" type="text" value="">
                            </div>
                        </div>
                        <div class="control-group" >
                            <label class="control-label">加速网段</label>
                            <div class="controls">
                                <input class="input-xlarge focused"  name="speednet" type="text" value="">
                            </div>
                        </div>
                        
                        <div class="form-actions">
                            <button type="submit" data-taskid="" class="btn btn-primary">提交</button>
                            
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>
        <!-- /set mode  -->
        <!--/.fluid-container-->
        <link href="View/FHL/vendors/datepicker.css" rel="stylesheet" media="screen">
        <link href="View/FHL/vendors/uniform.default.css" rel="stylesheet" media="screen">
        <link href="View/FHL/vendors/chosen.min.css" rel="stylesheet" media="screen">
        <link href="View/FHL/vendors/wysiwyg/bootstrap-wysihtml5.css" rel="stylesheet" media="screen">
        <link rel="stylesheet" href="View/FHL/vendors/morris/morris.css">


        <script src="View/FHL/vendors/jquery-1.9.1.js"></script>
        <script src="View/FHL/bootstrap/js/bootstrap.min.js"></script>
        <script src="View/FHL/vendors/datatables/js/jquery.dataTables.min.js"></script>

        <script src="View/FHL/vendors/jquery.uniform.min.js"></script>
        <script src="View/FHL/vendors/chosen.jquery.min.js"></script>
        <script src="View/FHL/vendors/bootstrap-datepicker.js"></script>

        <script src="View/FHL/assets/DT_bootstrap.js"></script>
        <script src="View/FHL/vendors/wysiwyg/wysihtml5-0.3.0.js"></script>
        <script src="View/FHL/vendors/wysiwyg/bootstrap-wysihtml5.js"></script>

        <script src="View/FHL/vendors/wizard/jquery.bootstrap.wizard.min.js"></script>
		<script src="View/FHL/vendors/jGrowl/jquery.jgrowl.js"></script>

        <script src="View/FHL/assets/scripts.js"></script>

        <script src="View/FHL/vendors/raphael-min.js"></script>
        <script src="View/FHL/vendors/morris/morris.min.js"></script>
        <script src="View/FHL/assets/echarts.min.js"></script>
        <script>
        var curtaskid = 0;

        $(function() {
            //refreshTask();
            
            $(".uniform_on").uniform();

            $('.textarea').wysihtml5();
			$('.form').submit(function() {return false;});
           //打开设置页面
            $('table').on("click",".showSetMode",
                    function(e){
                        //console.log($(this).parent().siblings('td').text());
                        curtaskid = $(this).data('id');
                       
                        var curname = $(this).data('name');
                        $('input[name=localport]').val($(this).data('localport'));
                        $('input[name=remoteip]').val($(this).data('remoteip'));
                        $('input[name=remoteport]').val($(this).data('remoteport'));
                        $('input[name=speednet]').val($(this).data('speednet'));
                       if(curname == '服务端'){
                        //服务端 只显示监听端口
                        $('input[name=remoteip]').parent().parent().addClass("hidden");
                        $('input[name=remoteport]').parent().parent().addClass("hidden");
                        $('input[name=speednet]').parent().parent().addClass("hidden");
                        $('input[name=localport]').parent().parent().removeClass("hidden");
                       }else{
                        $('input[name=remoteip]').parent().parent().removeClass("hidden");
                        $('input[name=remoteport]').parent().parent().removeClass("hidden");
                        $('input[name=speednet]').parent().parent().removeClass("hidden");
                        $('input[name=localport]').parent().parent().addClass("hidden");
                       } 
                        $('#setMode').modal('show');
                    }
            );
            //修改任务参数后 提交
            $(".form :submit").click(function(){
				var postdata = $(this).closest("form").serializeArray();
				postdata.push(
                    {
                        name:"id",
                        value: curtaskid,
                    },
                    {
                        name:"type",
                        value: 'TCPG',
                    },
                );
				console.log(postdata);
				$.post("{php HYBBS_URL('task','editTask');}", postdata,  function(e){
					if(e.error){
                        window.location.reload();
						
					}else{
						$.jGrowl(e.info);
					}

				},'json');

			});
           
           
//打开tcp加速操作命令
            $("#start").click(function (e){
                $.get("?task/restartTask?", {
                    type:'tcp_g',
                    mode:$('#mode').val(), 
                    rip:$('#rip').val(),
                    //rport:$('#rport').val(),
                    //destination:$('#destination').val(),
                    //netmask:$('#netmask').val(),
                    //localGate:$('#localGate').val(),
                    //remoteGate:$('#remoteGate').val(),
                },  function(ee){
                    if(ee.state){
                        $.jGrowl(ee.info);
                        location.reload();
                    }else{
                        $.jGrowl(ee.info);
                    }
                },'json');

            });
//关闭tcp加速
            $("#stop").click(function (e){
                $.get("?task/killTask?", {
                    type:'tcp_g',
                },  function(ee){
                    if(ee.state){
                        $.jGrowl(ee.info);
                        location.reload();
                    }else{
                        $.jGrowl(ee.info);
                    }
                },'json');
            });
//直通  这里不用了
            $("#direct").click(function (e){
                $.get("?task/directRoute?", {
                    destination:$('#destination').val(),
                    netmask:$('#netmask').val(),
                    rip:$('#rip').val()
                },  function(ee){
                    if(ee.state){
                        $.jGrowl(ee.info);
                        location.reload();
                    }else{
                        $.jGrowl(ee.info);
                    }
                },'json');
            });
//自检按钮
            $("#autoTest").click(function (e){
                $.jGrowl("系统正在自检,需要约2分钟。。。。");
                $.get("?task/autoTest?", {
                    'type':'tcp_g',
                    
                },  function(ee){
                    if(ee.state){
                        $('#sysTestContent').empty();
                        for(var i in ee.info){
                            $('#sysTestContent').append("<pre>"+ee.info[i]+"</pre>");
                        }
                        $('#sysTestModal').modal('show')
                    }else{
                        $.jGrowl(ee.info);
                    }
                },'json');
            });

            
        });
        </script>
    </body>

</html>